

require('/utils/Page')
const utils = require('/utils/util');
//import formatTime,{formatNumber} from '/utils/util'
console.log(utils)
let $https = require('/utils/request')
wx.$https = $https
wx.baseURL = $https.baseURL
wx.get = $https.get
wx.put = $https.put
wx.post = $https.post
wx.delete = $https.delete
wx.cloud.init({
    env: 'cloud1-3gkx7h7i9a6be10e'
})
App({
  onLaunch() {

    const db = wx.cloud.database()
    db.collection('user').where({
        _openid: 'opUX95aAugcT1N065p9Cao2e5w0w',
        done: true
      }).get({
        success: function(res) {
          // res.data 包含该记录的数据
          console.log('get',res.data)
        }
      })
      wx.chooseImage({
        success: chooseResult => {
          // 将图片上传至云存储空间
          wx.cloud.uploadFile({
            // 指定上传到的云路径
            cloudPath: 'my-photo.png',
            // 指定要上传的文件的小程序临时文件路径
            filePath: chooseResult.tempFilePaths[0],
            // 成功回调
            success: res => {
              console.log('上传成功', res)
            },
          })
        },
      })
    wx.cloud.callFunction({
        // 云函数名称
        name: 'helloworld',
        // 传给云函数的参数
        data: {
          a: 1,
          b: 2,
        },
        success: function(res) {
          console.log(res) // 3
        },
        fail: console.error
      })
    // 展示本地存储能力
    const logs = wx.getStorageSync('logs') || []
    logs.unshift(Date.now())
    wx.setStorageSync('logs', logs)

    // 登录
    wx.login({
      success: res => {
        console.log('I am wx.login',res)
        wx.get('http://localhost:3000/wxlogin?code=' + res.code).then(res => {
          wx.userInfo = res
          wx.token = res.token
          if(wx.waitLoginPages.length) {
            for(let i = 0; i < wx.waitLoginPages.length; i ++) {
              let page = wx.waitLoginPages[i]
              page.onLoad.call(page.context,page.options)
            }
          }
        })
        // 发送 res.code 到后台换取 openId, sessionKey, unionId
      }
    })
  },
  globalData: {
    userInfo: null
  }
})
